package com.ryenlii.datatrans.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ryenlii.datatrans.common.model.RequestModel;
import com.ryenlii.datatrans.core.Result;
import com.ryenlii.datatrans.core.ResultGenerator;
import com.ryenlii.datatrans.entity.Student;
import com.ryenlii.datatrans.service.StudentService;
import com.taosdata.jdbc.TSDBDriver;

import jakarta.annotation.Resource;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

/**
 * 学生管理
 *
 * @author zhengwen
 */
@Slf4j
@RestController
@RequestMapping("/student/{lang}")
public class StudentController {
    @Resource
    private StudentService studentService;

    /**
     * 新增
     *
     * @param record 学生信息
     * @param lang   国际化
     * @return 统一出参
     */
    @PostMapping("/add")
    public Result<?> add(@RequestBody Student record, @PathVariable(value = "lang") String lang) {
        return studentService.add(record, lang);
    }

    /**
     * 修改
     *
     * @param record 学生信息
     * @param lang   国际化
     * @return 统一出参
     */
    @PutMapping("/update")
    public Result<?> update(@RequestBody Student record, @PathVariable(value = "lang") String lang) {
        return studentService.update(record, lang);
    }

    /**
     * 分页查询
     *
     * @param requestModel 查询条件
     * @return 统一出参
     */
    @PostMapping("/getPage")
    public Result<?> selectPage(@RequestBody RequestModel<Student> requestModel) {
        Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
        Assert.notNull(requestModel.getPage(), "page 不能为空");
        IPage<Student> record = studentService.selectPage(requestModel.getPage(), requestModel.getCustomQueryParams());
        return ResultGenerator.genSuccessResult(record);
    }

    @GetMapping("/get/{id}")
    public Result<?> get(@PathVariable("id") Long id) {
        studentService.get(id);
        return ResultGenerator.genSuccessResult();
    }

}
